package com.bestcem.xm.ticket.controller.vo;

import com.alibaba.fastjson.JSONArray;
import com.bestcem.xm.ticket.grpc.client.dto.survey.MemberNodeDTO;
import com.bestcem.xm.ticket.grpc.client.dto.survey.RespondentDTO;
import com.bestcem.xm.ticket.grpc.client.dto.survey.RespondentExtraDTO;
import com.bestcem.xm.ticket.grpc.client.enums.RespondentClientTypeEnum;
import com.bestcem.xm.ticket.grpc.client.enums.survey.RespondentDataStatusEnum;
import com.bestcem.xm.ticket.grpc.client.enums.survey.RespondentSourceEnum;
import com.bestcem.xm.ticket.grpc.client.enums.survey.RespondentStatusEnum;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * @author zq.ding <zq.ding@idiaoyan.com>
 * @version v1.0
 * @date 2021/9/10 19:05
 */
@ToString
@Getter
@Setter
public class RespondentVO {

    /**
     * 主键
     */
    String id;

    /**
     * Required 答卷数据 map
     * [
     * {
     * "gid": 2,
     * "cid": "Q1",
     * "_index": "Q1",
     * "title": "单选题",
     * "qtype": "single",
     * "custom_qtype": "single",
     * "answer": [
     * {
     * "gid": 3,
     * "seq": 3,
     * "title": "选项1",
     * "open": "赵明"
     * }
     * ]
     * }
     * ]
     */
    List<Map<String, Object>> answers;

    /**
     * 问卷ID
     */
    @JsonProperty("project_id")
    String projectId;

    /**
     * 数据状态
     *
     * @see RespondentDataStatusEnum
     */
    @JsonProperty("data_status")
    Integer dataStatus;

    /**
     * 答卷状态
     *
     * @see RespondentStatusEnum
     */
    @JsonProperty("hhstatus")
    Integer status;

    /**
     * 废弃前的状态，用于恢复
     */
    @JsonProperty("pre_discard_status")
    Integer preDiscardStatus;

    /**
     * 答卷序号
     */
    @JsonProperty("seq")
    Long seq;

    /**
     * 是否转换
     */
    @JsonProperty("parsed")
    Boolean parsed;

    /**
     * 答卷版本
     */
    @JsonProperty("version")
    Integer version;

    /**
     * 数据来源
     *
     * @see RespondentSourceEnum
     */
    @JsonProperty("source")
    Integer source;

    /**
     * 答卷归属ID
     */
    @JsonProperty("group_id")
    String groupId;

    /**
     * 答卷归属编码
     */
    @JsonProperty("group_code")
    String groupCode;

    /**
     * 答题人ID
     */
    @JsonProperty("person_id")
    String personId;

    /**
     * HTTP userAgent头部信息
     */
    @JsonProperty("user_agent")
    String userAgent;

    /**
     * 答题终端类型
     *
     * @see RespondentClientTypeEnum
     */
    @JsonProperty("client_type")
    Integer clientType;

    /**
     * 答题IP
     */
    @JsonProperty("ip")
    String ip;

    /**
     * 开始答题时间
     */
    @JsonProperty("begin_time")
    //@JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    LocalDateTime beginTime;

    /**
     * 结束答题时间
     */
    @JsonProperty("finish_time")
    //@JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    LocalDateTime finishTime;

    /**
     * rspdDataId
     */
    String rspdDataId;

    /**
     * rspdWeixinId
     */
    String rspdWeixinId;

    /**
     * rspdLocationId
     */
    String rspdLocationId;

    /**
     * rspdExtraId
     */
    String rspdExtraId;

    /**
     * rspdAttachmentId
     */
    String rspdAttachmentId;

    /**
     * 外部系统的seq
     */
    @JsonProperty("ext_seq")
    String extSeq;

    /**
     * 提交序列
     */
    @JsonProperty("submit_seq")
    Long submitSeq;

    /**
     * ip城市
     */
    @JsonProperty("ip_country")
    String ipCountry;

    /**
     * ip省份
     */
    @JsonProperty("ip_province")
    String ipProvince;

    /**
     * ip城市
     */
    @JsonProperty("ip_city")
    String ipCity;

    /**
     * 备注
     */
    @JsonProperty("remark")
    String remark;

    /**
     * 联系人id
     */
    @JsonProperty("member_id")
    String memberId;

    /**
     * 当前语言
     */
    @JsonProperty("current_lang")
    String currentLang;

    /**
     * 投放id
     */
    @JsonProperty("deliver_id")
    String deliverId;

    /**
     * 投放组id
     */
    @JsonProperty("deliver_group_id")
    String deliverGroupId;

    /**
     * 二次投放记录id
     */
    @JsonProperty("again_deliver_record_id")
    String againDeliverRecordId;

    /**
     * 该样本所有的配额项集合
     * FIXME: 注意这个字段, 从数组改成了JSON数组
     */
//    @JsonProperty("quota_checkitem_list")
    String quotaCheckitemList;

    /**
     * 记录创建时间
     */
    @JsonProperty("created_dt")
    //@JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    LocalDateTime createdDt;

    /**
     * 预生成csv状态标记
     */
    @JsonProperty("excel_parsed")
    Boolean excelParsed;

    /**
     * surveyGids
     */
    @JsonProperty("survey_gids")
    List<Integer> surveyGids;

    /**
     * 用户微信信息
     */
    String wxInfo;

    /**
     * 专用链接投放专用码
     */
    @JsonProperty("ded_code")
    String dedCode;

    /**
     * 样本投放surveyunion拼接上的参数
     */
    String idySid;

    /**
     * 总分
     */
    @JsonProperty("score")
    Double score;

    /**
     * Required 额外内容
     */
    RespondentExtraDTO extra;

    /**
     * Required 成员姓名
     */
    MemberNodeDTO member;

    /**
     * Required 成员标签
     */
    List<String> memberTags;

    /**
     * Required 外部参数
     */
    JSONArray ext;

    /*-----------------FilledRespondentInfoDTO有但RespondentDTO没有的参数，进行添加---------------------*/
    /**
     * Required 耗时
     */
    @JsonProperty("time_cost")
    String costTime;

    /**
     * 答卷状态
     *
     * @see RespondentStatusEnum
     */
    @JsonProperty("status")
    Integer respondentStatus;

    /**
     * 该样本所有的配额项集合
     */
    @JsonProperty("quota_checkitem_list")
    List<String> quotaCheckItems;

    /**
     * 记录创建时间
     */
    @JsonProperty("create_time")
    //@JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    LocalDateTime createTime;

    /**
     * 结束答题时间
     */
    @JsonProperty("end_time")
    //@JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    LocalDateTime endTime;

    /**
     * 开始答题时间
     */
    @JsonProperty("start_time")
    //@JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
    LocalDateTime startTime;

    /**
     * respondent_attachment_id
     */
    @JsonProperty("rspd_attachment_id")
    String attachmentId;

    /**
     * Required 浏览器
     */
    String browser;

    /**
     * 备注
     */
    String comment;

    /**
     * respondent_data_id
     */
    @JsonProperty("rspd_data_id")
    String dataId;

    /**
     * Required 投放方式
     */
    @JsonProperty("deliver_channel")
    String deliverChannel;

    /**
     * 专用链接投放专用码
     */
    String deliverCode;

    /**
     * Required 投放来源
     */
    @JsonProperty("deliver_source")
    String deliverSource;

    /**
     * respondent_extra_id
     */
    @JsonProperty("rspd_extra_id")
    String extraId;

    /**
     * Required 层级名
     */
    String group;

    /**
     * 样本投放survey_union拼接上的参数
     */
    @JsonProperty("idy_sid")
    String idySurveyUnionId;

    /**
     * respondent_location_id
     */
    @JsonProperty("rspd_location_id")
    String locationId;

    /**
     * Required 成员信息
     */
    @JsonProperty("member_info")
    String memberInfo;

    /**
     * Required 成员姓名
     */
    @JsonProperty("member_name")
    String memberName;

    /**
     * Required 操作系统
     */
    String os;

    /**
     * 答题人ID
     */
    String userId;

    /**
     * rspdWeixinId
     */
    @JsonProperty("rspd_weixin_id")
    String weixinId;

    /**
     * 用户微信信息
     */
    @JsonProperty("wx_info")
    String wxUserInfo;

    public static RespondentVO DtoToVO(RespondentDTO dto) {
        if (dto == null) {
            return null;
        }
        RespondentVO respondentVO = new RespondentVO();
        respondentVO.setId(dto.getId());
        respondentVO.setProjectId(dto.getProjectId());
        respondentVO.setDataStatus(dto.getDataStatus());
        respondentVO.setStatus(dto.getStatus());
        respondentVO.setPreDiscardStatus(dto.getPreDiscardStatus());
        respondentVO.setSeq(dto.getSeq());
        respondentVO.setParsed(dto.getParsed());
        respondentVO.setVersion(dto.getVersion());
        respondentVO.setSource(dto.getSource());
        respondentVO.setGroupId(dto.getGroupId());
        respondentVO.setGroupCode(dto.getGroupCode());
        respondentVO.setPersonId(dto.getPersonId());
        respondentVO.setUserAgent(dto.getUserAgent());
        respondentVO.setClientType(dto.getClientType());
        respondentVO.setIp(dto.getIp());
        respondentVO.setBeginTime(dto.getBeginTime());
        respondentVO.setFinishTime(dto.getFinishTime());
        respondentVO.setRspdDataId(dto.getRspdDataId());
        respondentVO.setRspdWeixinId(dto.getRspdWeixinId());
        respondentVO.setRspdLocationId(dto.getRspdLocationId());
        respondentVO.setRspdExtraId(dto.getRspdExtraId());
        respondentVO.setRspdAttachmentId(dto.getRspdAttachmentId());
        respondentVO.setExtSeq(dto.getExtSeq());
        respondentVO.setSubmitSeq(dto.getSubmitSeq());
        respondentVO.setIpCountry(dto.getIpCountry());
        respondentVO.setIpProvince(dto.getIpProvince());
        respondentVO.setIpCity(dto.getIpCity());
        respondentVO.setRemark(dto.getRemark());
        respondentVO.setMemberId(dto.getMemberId());
        respondentVO.setCurrentLang(dto.getCurrentLang());
        respondentVO.setDeliverId(dto.getDeliverId());
        respondentVO.setDeliverGroupId(dto.getDeliverGroupId());
        respondentVO.setAgainDeliverRecordId(dto.getAgainDeliverRecordId());
        respondentVO.setQuotaCheckitemList(dto.getQuotaCheckitemList());
        respondentVO.setCreatedDt(dto.getCreatedDt());
        respondentVO.setExcelParsed(dto.getExcelParsed());
        respondentVO.setSurveyGids(dto.getSurveyGids());
        respondentVO.setWxInfo(dto.getWxInfo());
        respondentVO.setDedCode(dto.getDedCode());
        respondentVO.setIdySid(dto.getIdySid());
        respondentVO.setScore(dto.getScore());
        respondentVO.setExtra(dto.getExtra());
        respondentVO.setMember(dto.getMember());
        respondentVO.setMemberTags(dto.getMemberTags());
        //respondentVO.setExtParams(dto.getExtParams());
        respondentVO.setCostTime(dto.getCostTime());
        respondentVO.setRespondentStatus(dto.getRespondentStatus());
        respondentVO.setQuotaCheckItems(dto.getQuotaCheckItems());
        respondentVO.setCreateTime(dto.getCreateTime());
        respondentVO.setEndTime(dto.getEndTime());
        respondentVO.setStartTime(dto.getStartTime());
        respondentVO.setAttachmentId(dto.getAttachmentId());
        respondentVO.setBrowser(dto.getBrowser());
        respondentVO.setComment(dto.getComment());
        respondentVO.setDataId(dto.getDataId());
        respondentVO.setDeliverChannel(dto.getDeliverChannel());
        respondentVO.setDeliverCode(dto.getDeliverCode());
        respondentVO.setDeliverSource(dto.getDeliverSource());
        respondentVO.setExtraId(dto.getExtraId());
        respondentVO.setGroup(dto.getGroup());
        respondentVO.setIdySurveyUnionId(dto.getIdySurveyUnionId());
        respondentVO.setLocationId(dto.getLocationId());
        respondentVO.setMemberInfo(dto.getMemberInfo());
        respondentVO.setMemberName(dto.getMemberName());
        respondentVO.setOs(dto.getOs());
        respondentVO.setUserId(dto.getUserId());
        respondentVO.setWeixinId(dto.getWeixinId());
        respondentVO.setWxUserInfo(dto.getWxUserInfo());
        return respondentVO;
    }

}
